import Vue from "vue";

// eslint-disable-next-line no-undef
GLOBAL.vbus = new Vue();

import {
  getClass,
  timeToDate,
} from "@monkey.do/monkey";
import {
  handleDataEmpty,
  accAdd,
  Subtr,
  accMultiply,
} from "@/utils/utils";
import {
  dataFormatter,
} from "@/utils/index";
// const DDLogin = window.DDLogin;
// Vue.prototype.DDLogin = DDLogin;
import svgSpriteLoader from '@/utils/svg-sprite-loader';

import App from "./App";

const __svg__ = { path: './assets/images/icons/*.svg', name: 'assets/images/[hash].sprite.svg' };
svgSpriteLoader(__svg__.filename);

import {
  install,
} from "@rabbit.do/rabbit";
// 引入rabbit、monkey、element-ui样式
import "@rabbit.do/rabbit/lib/style.css";
import "@/assets/rabbit/theme/index.css";
import "@monkey.do/monkey/lib/theme-chalk/index.css";
import "@/assets/styles/index.scss";
// 引入字体
import "@/assets/rabbit/theme/fonts/element-icons.ttf";
import "@/assets/rabbit/theme/fonts/element-icons.woff";

// 引入rabbit图片
const req = require.context('./assets/rabbit/images', false, /\.(png|jpe|gif)$/);
const requireAll = requireContext => requireContext.keys().map(requireContext);
requireAll(req);

import {
  routes,
} from "@/routes";
import * as swanStore from "@/store";

import './directives/permission';
import axios from '@/plugins/axios';
import api from '@/plugins/api';
import consts from '@/plugins/const';
import crud from '@/plugins/crud';
import vui from './components';
import Verify from './components/Verify';
var pinyin = require("pinyin");
Vue.prototype.$pinyin = pinyin;
Vue.prototype.$api = api;
Vue.prototype.$ajax = axios;
Vue.prototype.$const = consts;
Vue.prototype.$crud = crud;

const setting = require("./settings");

const rabbit = install({
  store: swanStore,
  routes,
  setting,
  loadView: (item) => (resolve) => require([`@/views/${item.component}`], resolve),
});

const {
  store,
  router,
} = rabbit;

import directives from '@/directives/index';

// 全局方法挂载
Vue.prototype.getClass = getClass;
Vue.prototype.timeToDate = timeToDate;
Vue.prototype.dataFormatter = dataFormatter;
Vue.prototype.handleDataEmpty = handleDataEmpty;
Vue.use(directives);
Vue.use(vui);
Vue.use(Verify);

// eslint-disable-next-line no-extend-native
Number.prototype.add = (arg) => {
  return accAdd(arg, this);
};
// eslint-disable-next-line no-extend-native
Number.prototype.sub = (arg) => {
  return Subtr(this, arg);
};
// eslint-disable-next-line no-extend-native
Number.prototype.mult = (arg) => {
  return accMultiply(this, arg);
};

new Vue({
  el: "#app",
  router,
  store,
  render: h => h(App),
});

export {
  router,
  store,
};
